import java.io.IOException;
import java.io.InputStream;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.GUIControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class PlayVideoMPG extends MIDlet {
	private Player player;
	private Form form;
	private Display display;
	private Item item;

	public PlayVideoMPG() {
		// TODO Auto-generated constructor stub
		display = Display.getDisplay(this);
		form = new Form("Using MPG Video");
		InputStream in = getClass().getResourceAsStream("/phantom.mpg");
		try {
			player = Manager.createPlayer(in, "video/mpeg");
			player.realize();
			// Lấy video control là lớp GUIControl bằng player.getControl
			GUIControl videoControl = (GUIControl) player
					.getControl("GUIControl");
			item = (Item) videoControl.initDisplayMode(
					GUIControl.USE_GUI_PRIMITIVE, null);
			form.append(item);
			player.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MediaException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		display.setCurrent(form);
	}

}
